package scsc.pm;

import java.util.ArrayList;
import java.util.List;

import scsc.pub.db.DBManage;
import scsc.pub.db.PageListData;
import scsc.pub.data.DispatchStyle;
import scsc.pub.exception.UnifyUserException;
import scsc.web.oa.dispatchconsult.data.DispatchConsultData;
import scsc.web.oa.dispatchstyle.data.DispatchStyleData;

public class DispatchStylePm {
	public DispatchStylePm() {
	  }
	
	public void createDispatchStyle(DBManage dbmanage,
			DispatchStyleData formdata) throws
	      UnifyUserException {
		  DispatchStyle data = new DispatchStyle();    
		  data.setId( formdata.getId() );
		  data.setStyle(formdata.getStyle() );
		  data.setDeptCode( formdata.getDeptCode() );
		  data.setRemark( formdata.getRemark() );
	      dbmanage.sqlSave(data);
	  }
	
	public void deleteDispatchStyle(DBManage dbmanage, String id) throws
	    UnifyUserException {
	  String hql = "delete from scsc.pub.data.DispatchStyle where id=" + id;
	  dbmanage.sqlDelete(hql);
	}
	
	public void modifyDispatchStyle(DBManage dbmanage,
			DispatchStyleData formdata) throws
	      UnifyUserException {
		  DispatchStyle data = new DispatchStyle();    
		  data.setId( formdata.getId() );
		  data.setStyle(formdata.getStyle() );
		  data.setDeptCode( formdata.getDeptCode() );
		  data.setRemark( formdata.getRemark() );
		  dbmanage.sqlUpdate(data);

	  }
	
	public void selectDispatchConsult(DBManage dbmanage, DispatchStyleData formdata,
			            PageListData footer) {
			String id=formdata.getId() ;
			String style=formdata.getStyle() ;
			String deptcode=formdata.getDeptCode() ;
			String sqlStr = "select new scsc.web.oa.dispatchstyle.data.DispatchStyleData" +
			"(" +
			"d.id,d.style,d.deptCode,dept.deptname,d.remark"+
			")" +
			" from scsc.pub.data.DispatchStyle as d,scsc.pub.data.Department as dept" +
			" where d.deptCode=dept.deptcode";
			if (id != null && id.trim().length() >0) {
				sqlStr = sqlStr + " and d.id ='" + id.trim() + "'";
			}
			if (style!=null && style.trim().length() > 0) {
				sqlStr = sqlStr + " and d.style like '%" + style.trim() + "%'";
			}
			if (deptcode!=null && deptcode.trim().length() > 0) {
				sqlStr = sqlStr + " and d.deptCode='" + deptcode.trim() + "'";
			}
			dbmanage.sqlQueryPage(sqlStr, footer);
	}
	
	public ArrayList selectDispatchConsult(DBManage dbmanage, DispatchStyleData formdata) {
			String id=formdata.getId() ;
			String style=formdata.getStyle() ;
			String deptcode=formdata.getDeptCode() ;
			String sqlStr = "select new scsc.web.oa.dispatchstyle.data.DispatchStyleData" +
			"(" +
			"d.id,d.style,d.deptCode,dept.deptname,d.remark"+
			")" +
			" from scsc.pub.data.DispatchStyle as d,scsc.pub.data.Department as dept" +
			" where d.deptCode=dept.deptcode";
			if (id != null && id.trim().length() >0) {
				sqlStr = sqlStr + " and d.id ='" + id.trim() + "'";
			}
			if (style!=null && style.trim().length() > 0) {
				sqlStr = sqlStr + " and d.style like '%" + style.trim() + "%'";
			}
			if (deptcode!=null && deptcode.trim().length() > 0) {
				sqlStr = sqlStr + " and d.deptCode='" + deptcode.trim() + "'";
			}
			List result = dbmanage.sqlQuery(sqlStr);
		    return (ArrayList) result;
	}
	
	public java.util.ArrayList selectDispatchStyles(DBManage dbmanage,
			String deptcode) {
		StringBuffer sqlStr = new StringBuffer();
		sqlStr.append("select new scsc.web.oa.dispatchstyle.data.DispatchStyleData(");
		sqlStr
				.append("ds.id,ds.style,ds.deptCode,ds.remark");
		sqlStr
				.append(") from scsc.pub.data.DispatchStyle as ds where 1=1");
		if (deptcode.length()>0) {
			sqlStr.append(" and ds.deptCode='" + deptcode+"'");
		}
		List result = dbmanage.sqlQuery(sqlStr.toString());
		return (ArrayList) result;
	}
}
